package ProductManager;
import Method.Conexcute;

import java.io.IOException;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
@WebServlet(urlPatterns = "/Addproduct")
public class AddproductServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String name= request.getParameter("name");
        String type=request.getParameter("type");
        String shopid=request.getParameter("shopid");
        String price=request.getParameter("price");
        String number=request.getParameter("number");
        Conexcute conexcute=new Conexcute();
        System.out.println(type);
        System.out.println("insert into `product` (`pr_name`,`type`,`sh_id`,`price`,`number`) values ( '"+name+"', '"+type+"','"+shopid+"','"+price+"','"+number+"');");
        if(conexcute.execute("insert into `product` (`pr_name`,`type`,`sh_id`,`price`,`number`) values ( '"+name+"', '"+type+"','"+shopid+"','"+price+"','"+number+"');")){
            response.setContentType("text/html");
            response.setCharacterEncoding("UTF-8");
            response.getWriter().println("数据添加成功");
            response.sendRedirect("ProductManager/product.jsp");
        }
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
